const express = require("express");
// const cookieParser = require("cookie-parser");
// const session = require("express-session");
const multer = require("multer");

// 路由模块
const loginRoute = require("./router/login");
const registerRoute = require("./router/register");
const getUserRoute = require("./router/getUser");
const setUserRoute = require("./router/setUser");
const setPasswordRoute = require("./router/setPassword");
const setAvatarRoute = require("./router/setAvatar");
const importUserRoute = require("./router/importUser");
const exportUserRoute = require("./router/exportUser");

const app = express();
const upload = multer({dest:"./upload"});

// 注册中间件
app.use( express.urlencoded() );
app.use( express.static("./www") );
app.use( express.static("./upload") );
app.use( upload.any() );
// 注册状态存储技术支持：cookie-parser
// app.use( cookieParser() );
// 注册状态存储技术支持：express-session
// app.use( session({
//   secret: '千锋H5',  // 加密信息，可以随便写
//   resave: false,    // 强制保存session，默认为true，建议设置为false
//   saveUninitialized: true,    // 强制将未初始化的session存储，默认为true，建议为true
//   cookie: { maxAge: 1000 * 30 * 60 }    // 过期时间，毫秒数
// }) );


// 注册路由
app.post("/login", loginRoute);
app.post("/register", registerRoute);
app.post("/getuser", getUserRoute);
app.post("/setuser", setUserRoute);
app.post("/setpassword", setPasswordRoute);
app.post("/setavatar", setAvatarRoute);
app.post("/importuser", importUserRoute);
app.get("/exportuser", exportUserRoute);

// 注册路由的通用语法：
  // METHOD表示请求方式：get，post
  // routerUrl表示路由地址，表示前端请求的地址
  // routerFn表示路由功能
// app.METHOD("/routerUrl", routerFn);

app.listen(3000);
